﻿{% extends "base.html" %}

{% block content %}
<script language="javascript" src="/static/js/jquery-1.2.1.pack.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/js/jquery-calendar-pack.js" ></script>
<style type="text/css">@import url(/static/css/jquery-calendar.css);</style>
<script language="javascript" type="text/javascript">
$(document).ready (function() {
    	popUpCal.regional['zh-cn'] = {
		dateFormat: 'YMD-'};
	popUpCal.setDefaults(popUpCal.regional['zh-cn']);
   $('#start_date').calendar({autoPopUp: 'focus',yearRange: '-10:+0'});
	$('#end_date').calendar({autoPopUp: 'focus',yearRange: '-10:+0'});
	$('select[name="group"]').change(function(){
		var pid = $(this).val()
		if(pid==0){
			$('div.groups_pid').show()
			console.log(pid)
		}else{
			$('div.groups_pid').each(function(){
				if($(this).attr('pid') != pid){
					$(this).hide()
				}else{
					$(this).show()
				}
			})
		}
	})
});
 </script>

 <script language=javascript>

function show(id){
	if(document.getElementById("table_foot"+id).style.display=="none"){
		document.getElementById("table_foot"+id).style.display="block";
	}else{
		document.getElementById("table_foot"+id).style.display="none";
	}
}
function showall()
{
   for(var  i=0;i<document.form1.elements.length;i++){  
       var  e=document.form1.elements[i];  
	   if  (e.name  !=  'chkall'){
	   					if (e.name =='tt')
						{
							document.getElementById("table_foot"+e.value).style.display="block";
						}
		}
	}
}
function hideall()
{
   for(var  i=0;i<document.form1.elements.length;i++){  
       var  e=document.form1.elements[i];  
	   if  (e.name  !=  'chkall'){
	   					if (e.name =='tt')
						{
							document.getElementById("table_foot"+e.value).style.display="none";
						}
		}
	}
}
</script>
<script>  
function  CheckAll()  
{  
   for(var  i=0;i<document.form1.elements.length;i++){  
       var  e=document.form1.elements[i];  
       if  (e.name  !=  'chkall' && e.name  !=  'dagain'){  
             e.checked  =  document.form1.chkall.checked;
			 }
		else{
				if (document.form1.chkall.checked)
				{
					showall();
				}
				else
				{
					hideall();
				}
			}
   }  //end for
}  
</script> 
<script language=javascript>
//验证数字
function isNumber(input)
{   var number = "1234567890";
    var temp;
    var j=0;
    for (var i = 0; i < input.length; i++ )
    {
        temp = input.substring(i,i+1);
        if (number.indexOf(temp) == -1)
        {
            return (false);
        }
    }
}
function verify(form){
  if(form.startid.value!="0"){
		if(isNumber(form.startid.value)==false )
		{
			alert("customer id must be a number");
			form.startid.focus();
			return false;
		}
		if(isNumber(form.endid.value)==false )
		{
			alert("customer id must be a number");
			form.endid.focus();
			return false;
		}
		if((int(form.startid.value))>(int(form.endid.value)))
		{
			alert("the first cumstomer id must smaller than the second");
			return false;
		}
	}


return true;
 }

function changeagent()
{
 document.all.agent_id.options[0].selected=true;
}
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
	<form name='form1' id='form1' action="/allocation_do/" method='post' onsubmit='return verify(this);' >
<table width='80%' class='grid' cellspacing='1' align='center'><tr><td colspan='10' class='title' align="center">distribute Customs</td></tr>

{% if not s_id %}
<tr valign='middle' align='left'><td class='odd' width='25%'>Distribution by Program</td>
<td class='even'>
<select name="projects_id" onChange="changeagent()">>
<option value="0">Plz choose Program</option>
  {% for pj in pj %}
<option value="{{pj.id}}">{{pj.name}}</option>
  {% endfor %}
</select>&nbsp;&nbsp;if doesn't choose,will distribute All items customers to sales
</td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>Distribution by Agent</td>
<td class='even'>
<select name="agent_id">
<option value="0">Plz choose Agent</option>
  {% for agent in agent %}
<option value="{{agent.id}}">{{agent.name}}</option>
  {% endfor %}
</select>&nbsp;&nbsp;if doesn't choose,will distribute All items customers to sales
</td></tr>
{% endif %}

<tr valign='middle' align='left'><td class='odd' width='25%'>From sales</td>
<td class='even'>
  {% for s in sp %}
                <input type="checkbox" name="sids" value="{{s.id}}"  />{{s.name}} &nbsp;&nbsp;
  {% endfor %}
  <font color="red">{{errormsg}}</font>
</td></tr>
<tr valign='middle' align='left'><td class='odd' width='25%'>Color</td>
<td class='even'>
<input type="radio" name="interlevel" id="interlevel" value="" checked />All&nbsp;&nbsp;
<input type="radio" name="interlevel" id="interlevel" value="0" />NC&nbsp;&nbsp;
<input type="radio" name="interlevel" id="interlevel" value="1" />HI&nbsp;&nbsp;
<input type="radio" name="interlevel" id="interlevel" value="2" />SI&nbsp;&nbsp;
<input type="radio" name="interlevel" id="interlevel" value="3" />NI&nbsp;&nbsp;
<input type="radio" name="interlevel" id="interlevel" value="4" />NT&nbsp;&nbsp;
<input type="radio" name="interlevel" id="interlevel" value="5" />LI&nbsp;&nbsp;
  <font color="red">{{errormsg}}</font>
</td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>Reg time:</td>
<td class='even'>
From:<input type="text" id="start_date" name="start_date" value="{% if start_date %}{{start_date}}{% else %}begin{% endif %}" size="10" readonly="true"/>   To:<input type="text" id="end_date" name="end_date" value="{% if end_date %}{{end_date}}{% else %}now{% endif %}" size="10" readonly="true"/> 
</td></tr>
<!-- user group -->
<tr valign='middle' align='left'><td class='odd' width='25%'>Choose area group</td>
<td class='even'>
<select name="group">
<option value="0">All groups</option>
  {% for agent in sg %}
<option value="{{agent.id}}">{{agent.name}}</option>
  {% endfor %}
</select>&nbsp;&nbsp;if doesn't choose,will distribute All items customers to adminstrator
</td></tr>
<tr valign='middle' align='left'><td class='odd' width='25%'><font color="red">*</font>To sales</td>
<td class='even'>
  {% for sp in sp %}
		
         {% ifnotequal s_id sp.id %}
			<div style='float:left;' class="groups_pid" pid='{{sp.group}}'>
                <input type="checkbox" name="sp[{{sp.id}}]" value="1" onclick="show({{sp.id}})" />{{sp.name}} &nbsp;&nbsp;
				<!--传隐藏变量以给JS全先时识别显示全部SALES比例输入框.-->
				<input type="hidden" name="tt" value="{{sp.id}}" />
			</div>
         {% endifnotequal %}

  {% endfor %}
  <font color="red">{{errormsg}}</font>
</td></tr>


<tr valign='middle' align='left'><td class='odd' width='25%'>checkbox option</td>
<td class='even'><INPUT  onclick=CheckAll()  type=checkbox  name=chkall value="1" > select all
</td></tr>
<!-- 显示SALES分得的比例输入框-->
<tr valign='middle' colspan="2" ><td colspan="2">
  {% for sp in sp %}
<table width="100%" border="0" cellpadding="0" cellspacing="0" id="table_foot{{sp.id}}" style="display:none">
<tr valign='middle' align='left' >
<td class='odd' width='25%'>{{sp.name}}</td>
<td class='even' align="left">
<input type="text" name="sprate[{{sp.id}}]" /> %
</td>
</tr>
</table>
  {% endfor %}  <font color="red">{{errormsg2}}</font>
</td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>enter customers ID</td>
<td class='even'>from:<INPUT  type="text"  name="startid" value='0' > &nbsp;to:<INPUT  type="text"  name="endid" value='0'>
</td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>Whether the redistribution</td>
<td class='even'><input name="dagain" type="checkbox" value="1" /> <font color="red">If select,it will distribute all include which had been distributed</font>
</td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>Black color customers</td>
<td class='even'><input name="isblack" type="checkbox" value="1" /> <font color="red">If select,it will distribute all include which had been changed black color</font>
</td></tr>



<input type="hidden" name="s_id" value="{{s_id}}" />
<tr valign='middle' align='left'><td class='odd' width='25%'></td>
<td class='even'>&nbsp;<input type='submit' class='button' name='submit'  id='submit' value=' Submit '  />&nbsp;<input type='button' class='button' name='back'  id='reset' value=' Back ' onclick="javascrip:history.back(1)" /></form></td></tr>

<tr valign='middle' align='left'><td class='odd' width='25%'>Note:</td>
<td class='even'>
Only allocate the customers who haven't been allocated by average to the sales that you choosed
</td></tr>


<tr valign='middle' align='left'><td class='odd' width='25%'></td>

</table>


{% endblock %}
